﻿Imports Newtonsoft.Json

Public Class LogBiometricsManager

    Private manager As SQLManager

    Public Sub New()
        manager = New SQLManager
    End Sub




    
    Public Function deleteLogBiometricsByID(ByVal lID As String) As Boolean


        Dim query As String = "DELETE FROM `log_biometrics` WHERE id='" + lID + "'"
        manager.executeQuery(query)

        Return True
    End Function


   
    Public Function retrieveLogBioByDateOnly(ByVal fromDate As String, ByVal toDate As String) As List(Of LogBiometrics)
        Dim bioArr As New List(Of LogBiometrics)
        Dim query As String = "SELECT * FROM `log_biometrics` WHERE (time_log >= '" + fromDate + "' AND time_log <='" + toDate + "') ORDER BY time_log"


        Dim resultString As String = "" + manager.executeQuery(query)

        bioArr = JsonConvert.DeserializeObject(Of List(Of LogBiometrics))(resultString)


        Return bioArr
    End Function
  

    Public Function retrieveLogBioByDate(ByVal id As Integer, ByVal fromDate As String, ByVal toDate As String) As List(Of LogBiometrics)
        Dim bioArr As New List(Of LogBiometrics)
        Dim query As String = "SELECT * FROM `log_biometrics` WHERE employee_id='" + id.ToString + "' AND (time_log >= '" + fromDate + "' AND time_log <='" + toDate + "') ORDER BY time_log"


        Dim resultString As String = "" + manager.executeQuery(query)

        bioArr = JsonConvert.DeserializeObject(Of List(Of LogBiometrics))(resultString)


        Return bioArr
    End Function

    Public Function retrieveLogBioByEmployeeIDArray(ByVal empIdList As List(Of String)) As List(Of LogBiometrics)
        Dim bioArr As New List(Of LogBiometrics)
        If empIdList.Count <= 0 Then Return bioArr
        Dim query As String = "SELECT * FROM log_biometrics WHERE employee_id IN (" + String.Join(",", empIdList) + ")"
        Dim resultString As String = "" + manager.executeQuery(query)

        bioArr = JsonConvert.DeserializeObject(Of List(Of LogBiometrics))(resultString)

        If (resultString = "") Then
            MsgBox("NO DATA")
        End If
        Return bioArr
    End Function

    Public Function retrieveLogBio() As List(Of LogBiometrics)
        Dim bioArr As New List(Of LogBiometrics)
        Dim query As String = "SELECT * FROM log_biometrics"
        Dim resultString As String = "" + manager.executeQuery(query)

        bioArr = JsonConvert.DeserializeObject(Of List(Of LogBiometrics))(resultString)

        If (resultString = "") Then
            MsgBox("NO DATA")
        End If
        Return bioArr
    End Function

    Public Function retrieveBio() As List(Of Biometrics)
        Dim bioArr As New List(Of Biometrics)
        Dim query As String = "SELECT * FROM tbl_biometrics"
        Dim resultString As String = "" + manager.executeQuery(query)

        bioArr = JsonConvert.DeserializeObject(Of List(Of Biometrics))(resultString)

        If (resultString = "") Then
            MsgBox("NO DATA")
        End If
        Return bioArr
    End Function

    Function getLogsByEmployeeId(ByVal id As Integer) As List(Of LogBiometrics)

        Dim bioArr As New List(Of LogBiometrics)
        Dim query As String = "SELECT * FROM `log_biometrics` WHERE employee_id='" + id.ToString + "'"


        Dim resultString As String = "" + manager.executeQuery(query)

        bioArr = JsonConvert.DeserializeObject(Of List(Of LogBiometrics))(resultString)

        
        Return bioArr

    End Function



End Class
